package com.gopay.scheduler.job;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.common.cps.dao.cbrmb.CbRemitFtpFileDtlDAO;
import com.gopay.common.domain.cbrmb.CbRemitFtpFileDtl;
import com.gopay.scheduler.GopayBaseJob;
import com.gopay.scheduler.service.cbrmb.CbRmbRemitFtpFileService;

/**
 * 
 * @ClassName: CbRmbRemitFtpFileDownLoadJob
 * @Description: 汇款APIFTP文件处理
 * @author gd.cui
 * @date 2016年12月16日 下午3:00:02
 */
public class CbRmbRemitFtpFileDownLoadJob extends GopayBaseJob {
	// 日志
	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Resource(name = "cbRmbRemitFtpFileService")
	private CbRmbRemitFtpFileService cbRmbRemitFtpFileService;

	@Resource(name = "cbRemitFtpFileDtlDAO")
	private CbRemitFtpFileDtlDAO cbRemitFtpFileDtlDAO;

	@Override
	protected void doJobInternal() {
		String hql = "FROM CbRemitFtpFileDtl t WHERE t.downLoadState = :state and t.count < 7 ";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("state", "0");
		List<CbRemitFtpFileDtl> cbRemitFtpFileDtls = cbRemitFtpFileDtlDAO.findByHql(hql, param);
		logger.error("待处理文件数为："+cbRemitFtpFileDtls.size());
		for (CbRemitFtpFileDtl remitFile : cbRemitFtpFileDtls) {
			cbRmbRemitFtpFileService.downloadFtpFile(remitFile);
		}
	}
}
